#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDockWidget>
#include <QLabel>
#include <QPushButton>
#include <QVBoxLayout>
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    //给主窗口设置一个子窗口
    QDockWidget* dockWidget=new QDockWidget();
    //使用addDockWidget方法，把浮动窗口设置到子窗口中
    this->addDockWidget(Qt::LeftDockWidgetArea,dockWidget);

    dockWidget->setWindowTitle("浮动窗口");

    QWidget* container=new QWidget();
    dockWidget->setWidget(container);

    QVBoxLayout* layout=new QVBoxLayout();
    container->setLayout(layout);

    QLabel* label=new QLabel("这是一个QLabel");
    QPushButton* button=new QPushButton("这是按钮");
    layout->addWidget(label);
    layout->addWidget(button);

    //设置浮动窗口的允许的停靠位置
    dockWidget->setAllowedAreas(Qt::LeftDockWidgetArea|Qt::TopDockWidgetArea);
}

MainWindow::~MainWindow()
{
    delete ui;
}
